/*
Date:20210503 15:58pm
key:第一次用到了try catch 还熟悉了万能catch
            try{
        n=stoi(s);
        }
        catch(...){return 0;}
*/

class Solution {
public:
    void swap(char&a,char&b)
    {
        if(a!=b)
        {
            a=a^b;
            b=a^b;
            a=a^b;
        }
    }
    int reverse(int x) 
    {
        int flag=0;
        if(x>0){flag=0;}else{flag=1;x=abs(x);}

        string s=to_string(x);

        for(int i=0;i<s.size()/2;i++)
        {
            swap(s[i],s[s.size()-1-i]);
        }
        
        int n;
        try{
        n=stoi(s);
        }
        catch(...){return 0;}
        if(flag)
        {
            n=-1*n;
        }
        return n;
        

        
    }
};